package com.bot.nft.module.cm.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bot.common.pojo.CommonResult;
import com.bot.nft.core.enums.cm.Enum;
import com.bot.nft.module.cm.domain.bo.CmCarouselInfoBo;
import com.bot.nft.module.cm.domain.vo.CarouselQueryBo;
import com.bot.nft.module.cm.domain.vo.CmCarouselInfoVo;
import com.bot.nft.module.cm.service.ICmCarouselService;
import com.bot.nft.core.config.MinioUtil;
import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.PutObjectArgs;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 描述:首页轮播控制层
 * <p>
 * 时间: 2023-12-04 08:53
 * 负责人: 卢梦丽
 **/
@CrossOrigin
@RestController
@RequestMapping("/cm")
public class CarouselController {

    @Resource
    private ICmCarouselService iCmCarouselService;

    /**
     * 新增首页轮播
     *
     * @param cmCarouselInfoBo
     * @return
     */
    @PostMapping("/addCarousel.do")
    public CommonResult<Boolean> addCarouselCmInfo(@RequestBody CmCarouselInfoBo cmCarouselInfoBo) {

        Boolean addCarouselCmInfo = iCmCarouselService.addCarouselCmInfo(cmCarouselInfoBo);
        if (!addCarouselCmInfo) {
            return CommonResult.error();
        }


        return CommonResult.ok();
    }

    /**
     * 修改首页轮播
     *
     * @param cmCarouselInfoBo
     * @return
     */
    @PostMapping("/editCarousel.do")
    public CommonResult<Boolean> updateCarouselCmInfo(@RequestBody CmCarouselInfoBo cmCarouselInfoBo) {

        Boolean updateCarouselCmInfo = iCmCarouselService.updateCarouselCmInfo(cmCarouselInfoBo);
        if (!updateCarouselCmInfo) {
            return CommonResult.error();
        }

        return CommonResult.ok();
    }

    /**
     * 查看首页轮播
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/getCarousel.do")
    public CommonResult<CmCarouselInfoVo> getCarouselCmInfo(@PathVariable("id") String id) {

        CmCarouselInfoVo carouselCmInfo = iCmCarouselService.getCarouselCmInfo(id);
        return CommonResult.data(carouselCmInfo);

    }

    /**
     * 删除首页轮播
     *
     * @param id
     * @return
     */
    @GetMapping ("/{id}/delCarousel.do")
    public CommonResult<Boolean> delCarouselCmInfo(@PathVariable("id") String id) {

        Boolean delCarouselCmInfo = iCmCarouselService.delCarouselCmInfo(id);
        if (!delCarouselCmInfo) {
            return CommonResult.error();
        }

        return CommonResult.ok();
    }

    /**
     * 分页查询首页轮播
     *
     * @param carouselQueryBo
     * @param pageNo
     * @param pageSize
     * @return
     */
    @PostMapping("/{pageNo}/{pageSize}/listCarousel.do")
    public CommonResult<Page<CmCarouselInfoVo>> queryAuthorByPage(@RequestBody CarouselQueryBo carouselQueryBo, @PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {

        Page<CmCarouselInfoVo> cmCarouselInfoVoPageInfo = iCmCarouselService.queryCarouselByPage(carouselQueryBo.getKeyword(), carouselQueryBo.getStatus(), pageNo, pageSize);
        return CommonResult.data(cmCarouselInfoVoPageInfo);
    }

    /**
     * 调整首页轮播顺序（升序）
     *
     * @param id
     * @param carouselNum
     * @return
     */
    @GetMapping("/{id}/{carouselNum}/adjustCarouse.do")
    public CommonResult<Boolean> adjustCarouselCmInfo(@PathVariable("id") String id, @PathVariable("carouselNum") Integer carouselNum) {

        Boolean adjustCarouselCmInfo = iCmCarouselService.adjustCarouselCmInfo(id, carouselNum);
        if (!adjustCarouselCmInfo) {
            return CommonResult.error();
        }

        return CommonResult.ok();
    }

    /**
     * 调整首页轮播顺序（降序）
     *
     * @param id
     * @param carouselNum
     * @return
     */
    @GetMapping("/{id}/{carouselNum}/descAdjustCarouse.do")
    public CommonResult<Boolean> descAdjustCarouselCmInfo(@PathVariable("id") String id, @PathVariable("carouselNum") Integer carouselNum) {

        Boolean adjustCarouselCmInfo = iCmCarouselService.descAdjustCarouselCmInfo(id, carouselNum);
        if (!adjustCarouselCmInfo) {
            return CommonResult.error();
        }

        return CommonResult.ok();
    }


    /**
     * 禁用首页轮播
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/disCarousel.do")
    public CommonResult<Boolean> disCarouselCmInfo(@PathVariable("id") String id) {

        Boolean disCarouselCmInfo = iCmCarouselService.disCarouselCmInfo(id);
        if (!disCarouselCmInfo) {
            return CommonResult.error();
        }

        return CommonResult.ok();
    }

    /**
     * 启用首页轮播
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/{carouselNum}/startCarousel.do")
    public CommonResult<Boolean> startCarouselCmInfo(@PathVariable("id") String id, @PathVariable("carouselNum") Integer carouselNum) {

        Boolean startCarouselCmInfo = iCmCarouselService.startCarouselCmInfo(id, carouselNum);
        if (!startCarouselCmInfo) {
            return CommonResult.error();
        }

        return CommonResult.ok();
    }

    /**
     * 预览首页轮播
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/preCarouse.do")
    public CommonResult<CmCarouselInfoVo> preCarouselCmInfo(@PathVariable("id") String id) {

        CmCarouselInfoVo cmCarouselInfoVo = iCmCarouselService.preCarouselCmInfo(id);
        return CommonResult.data(cmCarouselInfoVo);

    }


}
